package com.diqye.templet.method;

import java.util.ArrayList;
import java.util.List;

import com.diqye.templet.core.Method;
/**
 * 根据大括号格式化字符串
 *
 * @author 秦振龙
 * @date 2013-7-8
 *
 * <b>修改记录及说明：</b>
 * <ul>
 * <li>2013-7-8  秦振龙  创建</li>
 * </ul>
 */
public class ArrayBraceMethodForSql implements Method {
	private int start = 1;
	private  Object[] objects;
	private List<Object> params = new ArrayList<Object>();
	public ArrayBraceMethodForSql(Object[] objects,int start){
		this(objects);
		this.start = start;
	}
	public ArrayBraceMethodForSql(Object[] objects){
		this.objects = objects;
	}
	
	public String invok(String str) {
		String rstr = str.substring(start,str.length()-1);
		int index = 0;
		if(rstr.matches("[0-9]+")){
			index = Integer.parseInt(rstr);
			if(index >= objects.length ){
				params.add(objects[index]);
				return "?";
			}
			index = index<0?0:index;
		}else{
			params.add(objects[index]);
			return "?";
		}
		
		/*if(objects[index] == null){
			return str;
		}*/
		params.add(objects[index]);
		return "?";
	}
	public List<Object> getParams() {
		return params;
	}
	
	

}
